package cassys.domain.classManagement;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

/**
 * @author Thurein
 */
public class Lecture implements Serializable {

    @Override
    public boolean equals(Object obj) {
        System.out.println("check equality for lectures");
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Lecture)) {
            return false;
        }
        final Lecture other = (Lecture) obj;
        System.out.println("Others : "+other.getName());
        System.out.println("this :"+this.name);
        
        System.out.println(this.name.equalsIgnoreCase(other.getName()));
        return this.name.equalsIgnoreCase(other.getName());
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }
    private Long lectureId;
    private String name;
    private Collection<Module> ownedModules;
    private Collection<Module> modules;

    public Lecture() {
        ownedModules = new ArrayList<Module>();
        modules = new HashSet<Module>();
        this.name= "";
    }

    public Lecture(String name) {
        this();
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public boolean isOwnerOf(Module module) {
        return this.ownedModules.contains(module);
    }

    public boolean isLectureOf(Module module) {
        return this.modules.contains(module);
    }

    public Long getLectureId() {
        return lectureId;
    }

    //keep protected to avoid assign invalid module from outside
    protected void setModuleOwner(Module module) {
        this.ownedModules.add(module);
        this.modules.add(module);
    }

    protected void removeOwnership(Module module) {
        this.ownedModules.remove(module);
        this.modules.remove(module);
    }

    protected void addModule(Module module) {
        this.modules.add(module);
    }

    /**
     * @param lectureId the lectureId to set
     */
    public void setLectureId(Long lectureId) {
        this.lectureId = lectureId;
    }
}
